#============================================================================================================================================================================================#
##Appendix Replication Files for "Counterinsurgency Tactics, Rebel Grievances, and Who Keeps Fighting"
rm(list=ls())

#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#loading packages
ipak <- function(pkg){  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("stargazer", "sensemakr", "xtable") 
ipak(packages)


#---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
##Reading in the Data
#setwd("")
data <- read.csv("MasterData.csv")

#============================================================================================================================================================================================#
#============================================================================================================================================================================================#
#============================================================TABLE A1==========================================================================================================#
#============================================================================================================================================================================================#
file.references <- read.csv("File_References_Replication.csv")
table(file.references)

#============================================================================================================================================================================================#
#============================================================================================================================================================================================#
#============================================================TABLE A2===============================================================================================#
#============================================================================================================================================================================================#
##Model 1
lm.appendix.mspc34.ind <- lm(War_Independence_All_Claim ~ Interned + citizen_army + military_service_pension_acts_1934, data=data)
summary(lm.appendix.mspc34.ind)

##Model 2
lm.appendix.mspc34.ind.all <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + rank_file + age + left_early 
                                 + early_join + + military_service_pension_acts_1934 + factor(easter_rising_location_endplace), data=data)
summary(lm.appendix.mspc34.ind.all)

##Results
stargazer(lm.appendix.mspc34.ind, lm.appendix.mspc34.ind.all, omit=c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================TABLE A3========================================================================================================#
#============================================================================================================================================================================================#
##Model 1
lm.appendix.indapproved1 <- lm(War_Independence_All_Approve ~ Interned + citizen_army , data=data)
summary(lm.appendix.indapproved1)

##MODEL 2
lm.appendix.indapproved2 <- lm(War_Independence_All_Approve ~ Interned + citizen_army  + rank_file + age + left_early 
                               + early_join + factor(easter_rising_location_endplace), data=data)
summary(lm.appendix.indapproved2)

##Results
stargazer(lm.appendix.indapproved1, lm.appendix.indapproved2, omit=c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================TABLE A4========================================================================================================#
#============================================================================================================================================================================================#
##Subsetting to Jacob's
g <- grepl("Jacob", data$easter_rising_location)
jacob.data <- data[g,]


##Model 1
lm.jacobs <- lm(War_Independence_All_Claim ~ Interned + citizen_army, data=jacob.data)
summary(lm.jacobs)

##Model 2
lm.jacobs.all.vars <- lm(War_Independence_All_Claim ~ Interned + citizen_army + rank_file + age + left_early + early_join, data=jacob.data)
summary(lm.jacobs.all.vars)

##Results
stargazer(lm.jacobs, lm.jacobs.all.vars)


#============================================================================================================================================================================================#
#============================================================TABLE A5===============================================================================================#
#============================================================================================================================================================================================#
##Subsetting to interned
data.interned <- subset(data, data$Interned==1)

##Model 1
lm.appendix.indlongimp1 <- lm(War_Independence_All_Claim ~ long_sentence + citizen_army , data=data.interned)
summary(lm.appendix.indlongimp1)

##Model 2
lm.appendix.indlongimp2 <- lm(War_Independence_All_Claim ~ long_sentence + citizen_army  + rank_file + age + left_early 
                              + early_join + factor(easter_rising_location_endplace), data=data.interned)
summary(lm.appendix.indlongimp2)

##Results
stargazer(lm.appendix.indlongimp1, lm.appendix.indlongimp2, omit=c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================TABLE A6===========================================================================================================#
#============================================================================================================================================================================================#
##Subsetting to rank and file
data.rank.file <- subset(data, data$rank_file==1)

##Model 1
lm.test.officers <- lm(organisation2_officers ~ Interned + citizen_army, data=data.rank.file)
summary(lm.test.officers)
stargazer(lm.test.officers)


#============================================================================================================================================================================================#
#============================================================TABLE A7===============================================================================================#
#============================================================================================================================================================================================#
##Model 1
lm.appendix.indanyclaim1 <- lm(War_Independence_Any_Claim ~ Interned + citizen_army , data=data)
summary(lm.appendix.indanyclaim1)

##MODEL 2
lm.appendix.indanyclaim2 <- lm(War_Independence_Any_Claim ~ Interned + citizen_army  + rank_file + age + left_early 
                               + early_join + factor(easter_rising_location_endplace), data=data)
summary(lm.appendix.indanyclaim2)

##Results
stargazer(lm.appendix.indanyclaim1, lm.appendix.indanyclaim2, omit=c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================Table A8===============================================================================================#
#============================================================================================================================================================================================#
##Table of ranks Above Volunteer/Private in Irish Volunteers
iv.data <- subset(data, data$citizen_army==0)
iv.data$organizations_rank <- iv.data$organisation1_rank
iv.table <- sort(table(iv.data$organisation1_rank), decreasing = TRUE)[3:length(table(iv.data$organisation1_rank))]

##removing volunteers/privates
iv.table <- iv.table[-4]
iv.table <- iv.table[-11]
iv.table <- iv.table[-33]

##Table A8
iv.table
xtable(iv.table)


#============================================================================================================================================================================================#
#============================================================Table A9===============================================================================================#
#============================================================================================================================================================================================#
##MODEL 1
lm.appendix.rank1 <- lm(War_Independence_All_Claim ~ Interned + citizen_army + factor(organisation1_rank), data=data)
summary(lm.appendix.rank1)

##Model 2
lm.appendix.rank2 <- lm(War_Independence_All_Claim ~ Interned + citizen_army + age + left_early 
                        + early_join + factor(organisation1_rank)  + factor(easter_rising_location_endplace), data=data)
summary(lm.appendix.rank2)

##Results
stargazer(lm.appendix.rank1, lm.appendix.rank2, omit=c("organisation1_rank", "easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================Table A10===============================================================================================#
#============================================================================================================================================================================================#
##MODEL 1 
lm.appendix.rankunknown1 <- lm(War_Independence_All_Claim ~ Interned + citizen_army + rank_file + rank_unknown, data=data)
summary(lm.appendix.rankunknown1)


##Model 2 
lm.appendix.rankunknown2 <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + rank_file + rank_unknown + age + left_early 
                               + early_join + factor(easter_rising_location_endplace), data=data)
summary(lm.appendix.rankunknown2)

##Results
stargazer(lm.appendix.rankunknown1, lm.appendix.rankunknown2, omit=c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================Table A11===============================================================================================#
#============================================================================================================================================================================================#
##Model 1 
lm.appendix.easterlocstart1 <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + factor(easter_rising_location_startplace), data=data)
summary(lm.appendix.easterlocstart1)

##MODEL 2 
lm.appendix.easterlocstart2 <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + rank_file + age + left_early 
                             + early_join + factor(easter_rising_location_startplace), data=data)
summary(lm.appendix.easterlocstart2)

##Results
stargazer(lm.appendix.easterlocstart1, lm.appendix.easterlocstart2, omit=c("easter_rising_location_startplace"))


#============================================================================================================================================================================================#
#============================================================Table A12===============================================================================================#
#============================================================================================================================================================================================#
##MODEL 1
lm.appendix.dublinbrigade1 <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + dublin_brigade, data=data)
summary(lm.appendix.dublinbrigade1)

##MODEL 2
lm.appendix.dublinbrigade2 <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + rank_file + age + left_early + early_join + dublin_brigade, data=data)
summary(lm.appendix.dublinbrigade2)

##Results
stargazer(lm.appendix.dublinbrigade1, lm.appendix.dublinbrigade2)


#============================================================================================================================================================================================#
#============================================================TABLE A13 & FIGURE A6===============================================================================================#
#============================================================================================================================================================================================#
##Sensitivity Analyses
lm.fight.intern.org.ind.all.vars <- lm(War_Independence_All_Claim ~ Interned + citizen_army + rank_file + age + left_early + early_join + factor(easter_rising_location_endplace), data=data)
summary(lm.fight.intern.org.ind.all.vars)

# runs sensemakr for sensitivity analysis
sensitivity.independence <- sensemakr(lm.fight.intern.org.ind.all.vars, treatment = "Interned",
                                      benchmark_covariates = "age",
                                      kd = c(5, 10, 15))
sensitivity.independence
summary(sensitivity.independence)

pdf(file="Sensitivity_Independence.pdf")
plot(sensitivity.independence)
dev.off()

#============================================================================================================================================================================================#
#============================================================TABLE A14===============================================================================================#
#============================================================================================================================================================================================#
##Including Individuals Killed
dead.pension.series <- 99

intern.dummy <- c(rep(1, 38), rep(0,61))

continue.fighting.dummy <- rep(1, dead.pension.series)

new.interned.w.dummy <- c(data$Interned, intern.dummy)

new.continuedfighting.w.dummy <- c(data$War_Independence_All_Claim, continue.fighting.dummy)

lm.deadseries <-  lm(new.continuedfighting.w.dummy ~ new.interned.w.dummy)
summary(lm.deadseries)
stargazer(lm.deadseries)


#============================================================================================================================================================================================#
#============================================================TABLE A15===============================================================================================#
#============================================================================================================================================================================================#
##Model 1
lm.appendix.joined1913 <- lm(War_Independence_All_Claim ~ Interned + citizen_army + joined_1913, data=data)
summary(lm.appendix.joined1913)

##MODEL 2
lm.appendix.joined1913.all <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + rank_file + age + left_early 
                                 + joined_1913 + factor(easter_rising_location_endplace), data=data)
summary(lm.appendix.joined1913.all)

##Results
stargazer(lm.appendix.joined1913, lm.appendix.joined1913.all, omit=c("easter_rising_location_endplace"))


#============================================================================================================================================================================================#
#============================================================TABLE A16===============================================================================================#
#============================================================================================================================================================================================#
##Model 1
lm.appendix.countyfe <- lm(War_Independence_All_Claim ~ Interned + citizen_army + factor(county), data=data)
summary(lm.appendix.countyfe)

##MODEL 2
lm.appendix.countyfe.all <- lm(War_Independence_All_Claim ~ Interned + citizen_army  + rank_file + age + left_early 
                                 + early_join + factor(easter_rising_location_endplace) + factor(county), data=data)
summary(lm.appendix.countyfe.all)

##Results
stargazer(lm.appendix.countyfe, lm.appendix.countyfe.all, omit=c("easter_rising_location_endplace", "county"))
